//  Open RTS Engine
//  Game Engine
//  Author: Martin Dorazil
//  Date: 25.3.2013
//
//  Static global module for loading xml settings for application
//  using plugixml parser

#pragma once

#include <string>
#include <iostream>
#include "../xmlparser/pugixml.hpp"

// default settings
// screen
#define SCREEN_WIDTH_DEFAULT    800
#define SCREEN_HEIGHT_DEFAULT   600
#define SCREEN_BPP_DEFAULT      32
#define FULLSCREEN_DEFAULT      false

// file structure
#define TEXTURE_PATH_DEFAULT    "textures/"
#define SHADER_PATH_DEFAULT     "shaders/"
#define SCRIPT_PATH_DEFAULT     "scripts/"
#define MODELS_PATH_DEFAULT     "models/"

// font
#define FONT_PATH_DEFAULT       "font/"
#define FONT_FILE_DEFAULT       "ft.png"

// gui
#define GADGETS_PATH_DEFAULT    "gadgets/"
#define GUI_FILE_DEFAULT        "gamegui.lua"

// terrain
#define TERRAIN_PATH_DEFAULT    "terrain/"

// sky
#define SKY_PATH_DEFAULT        "sky/"

// water
#define WATER_PATH_DEFAULT      "water/"

// console settings
#define LOG_FILE_DEFAULT        "console_log.txt"
#define COM_FILE_DEFAULT        "command.txt"
#define CONSOLE_PATH_DEFAULT    "console/"
#define CONSOLE_FONT_DEFAULT    "ft.png"
#define CONSOLE_BACK_DEFAULT    "console.png"

const float MAX_ZOOM_DEFAULT = 45.0f;
const float MIN_ZOOM_DEFAULT = 20.0f;

#define CAM_MAXSTEP_DEFAULT 		  1000
#define CAM_DECELERATION_DEFAULT 	50
#define CAM_EDGE_SENS_DEFAULT		  10
/*
 Enumerator for setup loading function to load
 all settings or just specific part of settings
 */
typedef enum RTS_loadSettings
{
	RTS_LOAD_ALL = 1,
	RTS_LOAD_CONSOLE = 2,
	RTS_LOAD_SCREEN = 3,
	RTS_LOAD_SHADER = 4,
	RTS_LOAD_SCRIPT = 5,
	RTS_LOAD_MODEL = 6,
	RTS_LOAD_TEXTURE = 7,
	RTS_LOAD_GADGETS = 8,
	RTS_LOAD_FONTS = 9,
	RTS_LOAD_MAP = 10,
	RTS_LOAD_CAMERA = 11
};

/*
 Camera structure
 */
typedef struct cameraSettings
{
	float MaxZoom, MinZoom;
	int MaxStep, Deceleration, EdgeSens;

	// ctor
	cameraSettings() :
			MaxZoom(MAX_ZOOM_DEFAULT), MinZoom(MIN_ZOOM_DEFAULT), MaxStep(
					CAM_MAXSTEP_DEFAULT), Deceleration(CAM_DECELERATION_DEFAULT), EdgeSens(
					CAM_EDGE_SENS_DEFAULT)
	{
	}
} CameraSettings;

/*
 Main displayed screen settings,
 used for setup SDL engine
 size of screen, color depth and fullscreen mode
 */
typedef struct screenSettings
{
	int screenWidth, screenHeight, screenBpp;
	bool fullscreen;

	// ctor
	screenSettings() :
			screenWidth(SCREEN_WIDTH_DEFAULT), screenHeight(SCREEN_HEIGHT_DEFAULT), screenBpp(
					SCREEN_BPP_DEFAULT), fullscreen(FULLSCREEN_DEFAULT)
	{
	}
} ScreenSettings;

/*
 Engine file structure
 path to directories with textures,
 shaders, script and models
 */
typedef struct fileStructure
{
	std::string texturePath;
	std::string shaderPath;
	std::string scriptPath;
	std::string modelsPath;
	// ctor
	fileStructure() :
			texturePath(TEXTURE_PATH_DEFAULT), shaderPath(SHADER_PATH_DEFAULT), scriptPath(
					SCRIPT_PATH_DEFAULT), modelsPath(MODELS_PATH_DEFAULT)
	{
	}
} FileStructure;

/*
 Console settings
 name of file to save log from console
 name of command file with user defined commands
 path do console directory
 */
typedef struct consoleSettings
{
	std::string logFile;
	std::string commandFile;
	std::string consolePath;
	std::string consoleFont;
	std::string consoleBackground;
	// ctor
	consoleSettings() :
			logFile(LOG_FILE_DEFAULT), commandFile(COM_FILE_DEFAULT), consolePath(
					CONSOLE_PATH_DEFAULT), consoleFont(CONSOLE_FONT_DEFAULT), consoleBackground(
					CONSOLE_BACK_DEFAULT)
	{
	}
} ConsoleSettings;

/*
 Font structure
 settings of font used in game
 */
typedef struct fontSettings
{
	std::string fontPath;
	std::string fontFile;
	// ctor
	fontSettings() :
			fontPath(FONT_PATH_DEFAULT), fontFile(FONT_FILE_DEFAULT)
	{
	}
} FontSettings;

/*
 GUI
 structure with game user interface settings
 */
typedef struct guiSettings
{
	std::string gadgetsPath;
	std::string guiScript;
	// ctor
	guiSettings() :
			gadgetsPath(GADGETS_PATH_DEFAULT), guiScript(GUI_FILE_DEFAULT)
	{
	}
} GuiSettings;

/*
 Map file structure
 */
typedef struct mapFileStruct
{
	std::string terrainPath;
	std::string waterPath;
	std::string skyPath;
	// ctor
	mapFileStruct() :
			terrainPath(TERRAIN_PATH_DEFAULT), waterPath(WATER_PATH_DEFAULT), skyPath(
					SKY_PATH_DEFAULT)
	{
	}
} MapFileStruct;

namespace Engine
{
/*
 Extern data structure
 */
extern ScreenSettings screenSettings;
extern FileStructure fileStructure;
extern FontSettings fontSettings;
extern GuiSettings guiSettings;
extern MapFileStruct mapFileStruct;
extern ConsoleSettings consoleSettings;
extern CameraSettings cameraSettings;

/*
 loading settings from xml file
 write load report or error message to log files (stdout, stderr)
 you can load ALL settings needed in engine by settig flags to RTS_LOAD_ALL,
 or you can specify one or more part of settings which you need
 look at RTS_loadSettings enumerator
 */
void loadSettings(std::string file, unsigned int flags);

}

